package com.unlock;

import ch.qos.logback.core.util.TimeUtil;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;

import java.awt.*;
import java.awt.event.KeyEvent;
import java.util.Timer;
import java.util.concurrent.TimeUnit;

/**
 * @description:
 * @author: hzw
 * @time: 2024/3/28 13:38
 */
@Component
public class SystemUnlockConfig implements ApplicationRunner {
    @Override
    public void run(ApplicationArguments args) throws Exception {
        createUnlockRobot();
    }

    private void createUnlockRobot() {
        Robot robot;
        try{
            robot = new Robot();
        } catch (AWTException E) {
            throw new RuntimeException();
        }

        while (true) {
            try {
                TimeUnit.SECONDS.sleep(5);
                robot.keyPress(KeyEvent.VK_UP);
                TimeUnit.SECONDS.sleep(5);
                robot.keyPress(KeyEvent.VK_DOWN);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
